package com.gxa.controller;

import com.gxa.pojo.SecondsKill;
import com.gxa.utils.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: hw
 * Date: 2020/11/26 21:29
 * Description:
 * Version: V1.0
 */
@RestController
@RequestMapping("/secondskill")
@Api(value = "秒杀管理",tags = "秒杀管理API")
public class SecondsKillController {

    @Autowired(required = false)
    private ResponseData responseData;

    @RequestMapping(value = "/querySecondsKill",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "查看秒杀信息",notes = "查看秒杀信息",httpMethod = "GET")
    public ResponseData querySecondsKill(){
        Map map = new HashMap();
        map.put("goodsName","测试商品名称");
        map.put("skAst","2020-07-11 15:21:45");
        map.put("skAed","2020-08-11 15:21:45");
        map.put("sk_num",22);
        map.put("skMkstatus",1);
        if (map != null){
            responseData.setCode(200);
            responseData.setMsg("查询成功");
            responseData.setData(map);
        } else {
            responseData.setCode(500);
            responseData.setMsg("查询失败");
        }
        return responseData;
    }

    @RequestMapping(value = "/addSecondsKill",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "根据ID添加秒杀信息",notes = "根据ID添加秒杀信息",httpMethod = "POST")
    public ResponseData addSecondsKill(SecondsKill secondsKill){

        if (secondsKill != null){
            responseData.setCode(200);
            responseData.setMsg("添加成功");
//            responseData.setData(map);
        } else {
            responseData.setCode(500);
            responseData.setMsg("添加失败");
        }
        return responseData;
    }

    @RequestMapping(value = "/updateSecondsKillById",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "根据ID修改秒杀信息",notes = "根据ID修改秒杀信息",httpMethod = "POST")
    public ResponseData updateSecondsKillById(Integer skId){

        if (skId > 0){
            responseData.setCode(200);
            responseData.setMsg("修改成功");
//            responseData.setData(map);
        } else {
            responseData.setCode(500);
            responseData.setMsg("修改失败");
        }
        return responseData;
    }

    @RequestMapping(value = "/delSecondsKillById",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "根据ID删除秒杀信息",notes = "根据ID删除秒杀信息",httpMethod = "POST")
    public ResponseData delSecondsKillById(Integer skId){

        if (skId > 0){
            responseData.setCode(200);
            responseData.setMsg("删除成功");
//            responseData.setData(map);
        } else {
            responseData.setCode(500);
            responseData.setMsg("删除失败");
        }
        return responseData;
    }
}
